var vue = new Vue({
	el : '#pageDiv',
	data : {
		currentPage : 1,
		pageSize : 5,
		totalSize : 10,
		tableData: [],
		queryBtn : false,
		
		wareHouseVO : {
			houseId : '',
			positionId : '',
			locationId : '',
			housePosition : '',
			positionPoi : '',
			locationName : '',
			goodsName : '',
			sku : '',
			pageNum : '',
			pageSize : ''
		},
		
		wareHouseVO2:{
			
			entryDate : '',
			updateDate : '',
			houseId : '',
			houseName : '',
			positionId : '',
			positionName : '',
			goodsBarCode : '',
			goodsName : '',
			goodsDesc : '',
			goodsUnit : '',
			goodsPrice : '',
			goodsNum : '',
			sku : '',
			goodsType : '',
			goodsLocationId : '',
			goodsLocationName : ''
			
		},
		
		house : [],
		position : [],
		location : [],
		//form校验规则
		 rules:{
			 userCode:[
	            { required: true, message: '员工号', trigger: 'blur' }
	          ],
	          userName:[
		        { required: true, message: '用户名', trigger: 'blur' }
		      ],
		      email:[
			    { required: true, message: '邮箱', trigger: 'blur' }
			  ],
			  phone:[
				{ required: true, message: '手机', trigger: 'blur' }
			  ]
		  }
		
	},
	mounted(){
		this.initQuery();
	},
	methods : {
		initQuery(){
			$.ajax({
				url : COMMON_URL.URL+'wareHouseController/initAllQueryMessage',
				type : 'get',
				dataType : 'json',
				success : function(data){
					
					if(data.ok){
						
						var result = data.attrs;
						vue.house = result.house;
						vue.location = result.location;
						
					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('初始化失败','','error');
				}
			});
		},
		selectHouseForQuery(val){
			$.ajax({
				url : COMMON_URL.URL+"housAndPositionController/findPositionForQuery",
				type : 'get',
				dataType : 'json',
				data : {'houseId' : val},
				success : function(data){
					if(data.ok){
						vue.position = data.data;
					}else{
						swal(data.msg,'','warnging');
					}
				},
				error : function(data){
					swal('查询失败','','error');
				}
			});
		},
		editClick(row){
			
			this.wareHouseVO2 = row;
		},
		handleCurrentChange(val){
			this.currentPage = val;
			vue.onQuery(val,this.pageSize);
		},
		handleSizeChange(val){
			this.pageSize = val;
			vue.onQuery(this.currentPage,val);
		},
		onQueryForBtn(){
			
			this.queryBtn = true;
			
			this.wareHouseVO.pageNum = this.currentPage;
			this.wareHouseVO.pageSize = this.pageSize;
			
			$.ajax({
				url : COMMON_URL.URL+'wareHouseController/getGoodsTradeForQuery',
				type : 'post',
				contentType : 'application/json',
				data : JSON.stringify(vue.wareHouseVO),
				success : function(data){
					vue.queryBtn = false;
					if(data.ok){
						var val = data.data;
						vue.totalSize = val.length;
						vue.tableData = val;
					}else{
						swal(data.msg,'','warning');
					}
					
				},
				error : function(data){
					vue.queryBtn = false;
					swal('查询失败','','error');
				}
			});
			
		},
		onQuery(pageNum,pageSize){
			
			$.ajax({
				url : COMMON_URL.URL+'wareHouseController/getGoodsTrade',
				dataType : 'json',
				type : 'get',
				data : {
					'pageNum': pageNum,
					'pageSize' : pageSize
				},
				success : function(data){
					if(data.ok){
						var val = data.attrs;
						
						vue.totalSize = val.totalSize;
						vue.tableData = val.val;

					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('查询失败','','error');
				}
			});
			
		}
		
	}
});
vue.onQuery(vue.currentPage,vue.pageSize);